Arrays.copyOf vs. System.arraycopy :: 자주 쓰이는 메소드및 API 를 정리합니다.[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

자주 쓰이는 메소드및 API 를 정리합니다.
[1]
등록일:2008-03-10 10:53:20 (0%)
작성자:
제목:Arrays.copyOf vs. System.arraycopy
1.  고전적인  System.arraycopy  

Java에서  각종  array를  복사하는  경우에  사용되었던  방식이다.
입력받을  값에  미리  초기화해  놓아야  한다.

int[]  array  =  new  int[]  {  1,  2,  3,  4  };
int[]  copy  =  new  int[4];
System.arraycopy(array,  0,  copy,  0,  4);

그리고  source와  destination의  시작위치를  지정할  수  있지만,
경험상  잘  사용할  필요가  거의  없었다

2.  새로운  java.util.Arrays.copyOf  (JDK6)

int[]  array  =  new  int[]  {  1,  2,  3,  4  };
int[]  copy  =  Arrays.copyOf(array,  array.length);
int[]  other  =  Arrays.copyOf(array,  10);

입력  받을  값을  미리  세팅할  필요가  없다.  파라미터도  명시적이고...
other의  경우는  other[4]  ~  other[9]가  0으로  초기화된  길이가  10인  int[]로  생성된다  (Object라면  null이  들어간  array로)
(System.arraycopy와  동일한  Arrays.copyOfRange도  있다)

3.  성능  비교    (  clone  vs.  Arrays.copyOf  )
df

Clone        :  3156
arraycopy:  3187
copyOf      :  3157

셋  다  거의  비슷한  성능을  보여주었다.
결국  사용성이  편한  Arrays.copyOf의  승리

출처  :  http://vczx.tistory.com/
[본문링크] Arrays.copyOf vs. System.arraycopy
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=2455
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.